package com.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class CacheService {
    
    @Autowired
    public  StringRedisTemplate redisTemplate;

    public<V> void add(String key,V value){
        try {
            if(ObjectUtil.isNotNull(value)){
                redisTemplate.opsForValue()
                .set(key, value.toString());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new RuntimeException("数据缓存到reids失败");
        }
    }
    
}
